package santeclair.referentiel.optique.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import santeclair.lunar.framework.annotation.Code;
import santeclair.lunar.framework.annotation.HashCodeEquals;
import santeclair.lunar.framework.annotation.ToString;
import santeclair.lunar.framework.util.EqualsUtils;
import santeclair.lunar.framework.util.HashCodeUtils;
import santeclair.lunar.framework.util.ToStringUtils;
import santeclair.referentiel.optique.config.Constant;
import santeclair.referentiel.optique.referentiel.enumeration.GeometrieVerreEnum;

@Entity
@Table(name = "tr_geometrie_verre", catalog = Constant.SCHEMA_NAME, uniqueConstraints = @UniqueConstraint(columnNames = "code_geometrie_verre"))
public class GeometrieVerre implements java.io.Serializable {

    private static final long serialVersionUID = -8419958227323442528L;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "identifiant_geometrie_verre", unique = true, nullable = false)
    @ToString
    @HashCodeEquals
    private Integer identifiantGeometrieVerre;

    /**
     * <ul>
     * UNIFOCAUX/MI-DISTANCE : correspond aux codeGeometrieVerre AF, UN et MD
     * </ul>
     * <ul>
     * MULTIFOCAUX : correspond aux codeGeometrieVerre BI, TR et PR
     * </ul>
     */
    @Code
    @Column(name = "code_geometrie_verre", unique = true, nullable = false, length = 20)
    @Enumerated(EnumType.STRING)
    @ToString
    @HashCodeEquals
    private GeometrieVerreEnum codeGeometrieVerre;

    @Column(name = "libelle_geometrie_verre", nullable = false)
    @ToString
    @HashCodeEquals
    private String libelleGeometrieVerre;

    @Column(name = "code_opto10_geometrie_verre", unique = false, nullable = false, length = 50)
    @ToString
    @HashCodeEquals
    private String codeOpto10GeometrieVerre;

    @ManyToMany(fetch = FetchType.LAZY, targetEntity = TypeVision.class)
    @JoinTable(name = "tl_geometrie_verre_par_type_vision", catalog = Constant.SCHEMA_NAME, joinColumns = {@JoinColumn(name = "identifiant_geometrie_verre", nullable = false, updatable = false)}, inverseJoinColumns = {@JoinColumn(name = "identifiant_type_vision", nullable = false, updatable = false)})
    private Set<TypeVision> typeVisions;

    public GeometrieVerre() {
    }

    public Integer getIdentifiant() {
        return this.identifiantGeometrieVerre;
    }

    public void setIdentifiant(Integer identifiantGeometrieVerre) {
        this.identifiantGeometrieVerre = identifiantGeometrieVerre;
    }

    public GeometrieVerreEnum getCodeGeometrieVerre() {
        return this.codeGeometrieVerre;
    }

    public void setCodeGeometrieVerre(GeometrieVerreEnum codeGeometrieVerre) {
        this.codeGeometrieVerre = codeGeometrieVerre;
    }

    public String getCodeOpto10() {
        return this.codeOpto10GeometrieVerre;
    }

    public void setCodeOpto10(String codeOpto10GeometrieVerre) {
        this.codeOpto10GeometrieVerre = codeOpto10GeometrieVerre;
    }

    public Integer getIdentifiantGeometrieVerre() {
        return identifiantGeometrieVerre;
    }

    public void setIdentifiantGeometrieVerre(Integer identifiantGeometrieVerre) {
        this.identifiantGeometrieVerre = identifiantGeometrieVerre;
    }

    public String getLibelleGeometrieVerre() {
        return libelleGeometrieVerre;
    }

    public void setLibelleGeometrieVerre(String libelleGeometrieVerre) {
        this.libelleGeometrieVerre = libelleGeometrieVerre;
    }

    public String getCodeOpto10GeometrieVerre() {
        return codeOpto10GeometrieVerre;
    }

    public void setCodeOpto10GeometrieVerre(String codeOpto10GeometrieVerre) {
        this.codeOpto10GeometrieVerre = codeOpto10GeometrieVerre;
    }

    public Set<TypeVision> getTypeVisions() {
        return this.typeVisions;
    }

    public void setTypeVisions(Set<TypeVision> typeVisions) {
        this.typeVisions = typeVisions;
    }

    @Override
    public String toString() {
        return ToStringUtils.toString(this);
    }

    @Override
    public int hashCode() {
        return HashCodeUtils.hashCode(this);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsUtils.isEqual(this, obj);
    }

}
